package me.bincker.formwork.web.modules.system.controller

import me.bincker.formwork.web.core.entity.PermissionEntity
import me.bincker.formwork.web.test.ResultMatchers
import me.bincker.formwork.web.test.TestSession
import me.bincker.formwork.web.test.TestUtils
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.web.servlet.ResultActions
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
import org.springframework.web.context.WebApplicationContext

@RunWith(SpringRunner::class)
@SpringBootTest
class PermissionControllerTest {
    companion object{
        fun getAll(session: TestSession): List<PermissionEntity> {
            val result = session.mockMvc.perform(session.get("/permissions"))
                    .andExpect(ResultMatchers.IS_OK)
                    .andReturn()
            return TestUtils.deSerialiseJson(result.response.contentAsString)
        }
    }

    @Autowired
    private lateinit var webApplicationContext: WebApplicationContext

    @Test
    fun getAll(){
        val session = TestSession(webApplicationContext)
        session.login()
        println(getAll(session))
    }
}